package com.yzh.design.demo.impl;

import com.yzh.design.demo.ICouponDiscount;

import java.math.BigDecimal;

/**
 * 直减
 */
public class ZJCouponDiscount implements ICouponDiscount<String> {
    @Override
    public BigDecimal discountAmount(String couponInfo, BigDecimal skuPrice) {
        BigDecimal val = skuPrice.subtract(new BigDecimal(couponInfo));
        /*
         * 最终金额必须大于等于0
         * compareTo：调用方和入参方进行比较，相等返回0，大于1，小于-1
         * */
        if (val.compareTo(BigDecimal.ONE) < 1) return BigDecimal.ZERO;
        return val;
    }
}
